<?php
namespace app\client\wxpay;

include_once __DIR__ . '/wxpay/WxPay.Api.php';

class WxRefund {
    
    private $input = null;
    
    public static function refund($transactionId, $refundNo, $totalFee, $refundFee, $config) {
        $repResult = ['success' => false, 'msg' => '', 'err_code' => ''];
        $input = new \WxPayRefund();
        $input->SetTransaction_id($transactionId);
        $input->SetTotal_fee($totalFee * 100);
        $input->SetRefund_fee($refundFee * 100);
        $input->SetOut_refund_no($refundNo);
        $input->SetOp_user_id($config->GetMerchantId());
        $result = \WxPayApi::refund($config, $input);
        if($result['return_code'] === 'FAIL') { //退款失败
            $repResult['msg'] = $result['return_msg'];
        }else{
            if($result['result_code'] === 'FAIL'){
                $repResult['err_code'] = $result['err_code'];
                $repResult['msg'] = $result['err_code_des'];
            }else{
                $repResult['success'] = true;
            }
        }
        
        return $repResult;
        
    }
    
    
}